package com.example.controller;

import com.example.common.Result;
import com.example.entity.Payment;
import com.example.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/payment")
@Slf4j
public class PaymentController {
    private final PaymentService paymentService;
    
    @Value("${server.port}")
    private String serverPort;

    public PaymentController(PaymentService paymentService) {
        this.paymentService = paymentService;
    }

    @PostMapping("/create")
    public Result<Payment> create(@RequestBody Payment payment) {
        Payment result = paymentService.create(payment);
        log.info("*****插入结果：" + result);
        return Result.success(result);
    }

    @GetMapping("/get/{id}")
    public Result<Payment> getPaymentById(@PathVariable("id") Long id) {
        Payment payment = paymentService.getPaymentById(id);
        log.info("*****查询结果：" + payment);
        if (payment != null) {
            return Result.success(payment);
        } else {
            return Result.error("没有对应记录");
        }
    }

    @GetMapping("/port")
    public String getPort() {
        return serverPort;
    }
} 